package com.fzhucc.modules.expert.controller;

import com.fzhucc.annotation.Log;
import com.fzhucc.modules.expert.domain.dto.ExpertConsultationConfigEditDto;
import com.fzhucc.modules.expert.domain.dto.ExpertConsultationConfigQueryCriteria;
import com.fzhucc.modules.expert.service.ExpertConsultationConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* @author yyg
* @date 2023-10-20
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "专家库:专家线上咨询配置表管理")
@RequestMapping("/api/expertConsultationConfig")
public class ExpertConsultationConfigController {

    private final ExpertConsultationConfigService expertConsultationConfigService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('expertConsultationConfig:list')")
    public void exportExpertConsultationConfig(HttpServletResponse response, ExpertConsultationConfigQueryCriteria criteria) throws IOException {
        expertConsultationConfigService.download(expertConsultationConfigService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询专家线上咨询配置")
    @ApiOperation("查询专家线上咨询配置")
    @PreAuthorize("@el.check('expertConsultationConfig:list')")
    public ResponseEntity<Object> queryExpertConsultationConfig(ExpertConsultationConfigQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(expertConsultationConfigService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    /*@PostMapping
    @Log("新增专家线上咨询配置")
    @ApiOperation("新增专家线上咨询配置")
    @PreAuthorize("@el.check('expertConsultationConfig:add')")
    public ResponseEntity<Object> createExpertConsultationConfig(@Validated @RequestBody ExpertConsultationConfig resources){
        return new ResponseEntity<>(expertConsultationConfigService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改专家线上咨询配置")
    @ApiOperation("修改专家线上咨询配置")
    @PreAuthorize("@el.check('expertConsultationConfig:edit')")
    public ResponseEntity<Object> updateExpertConsultationConfig(@Validated @RequestBody ExpertConsultationConfig resources){
        expertConsultationConfigService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }*/

    @DeleteMapping
    @Log("删除专家线上咨询配置")
    @ApiOperation("删除专家线上咨询配置")
    @PreAuthorize("@el.check('expertConsultationConfig:del')")
    public ResponseEntity<Object> deleteExpertConsultationConfig(@RequestBody Integer[] ids) {
        expertConsultationConfigService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*@PostMapping(value = "/add")
    @Log("新增专家线上咨询配置 数组的形式")
    @ApiOperation("新增专家线上咨询配置 数组的形式")
    @PreAuthorize("@el.check('expertConsultationConfig:add')")
    public ResponseEntity<Object> createExpertConsultationConfig(@Validated @RequestBody ExpertConsultationConfigAddDto resources){
        return new ResponseEntity<>(expertConsultationConfigService.create(resources),HttpStatus.CREATED);
    }*/

    @PostMapping(value = "/saveList")
    @Log("专家线上咨询配置操作")
    @ApiOperation("专家线上咨询配置操作")
    public ResponseEntity<Object> editExpertConsultationConfig(@Validated @RequestBody ExpertConsultationConfigEditDto resources){
        return new ResponseEntity<>(expertConsultationConfigService.saveList(resources),HttpStatus.NO_CONTENT);
    }
}